package com.api.core.util;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class RspUtil {

    public static void returnsMsg(HttpServletResponse response, Object msg) {
        try {
            response.setContentType("text/html;charset=utf-8");
            PrintWriter out = response.getWriter();
            out.print(JSON.toJSON(msg));
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void returnObject(HttpServletResponse response, Object msg) {
        PrintWriter out = null;
        try {
            response.setContentType("application/json; charset=utf-8");
            out = response.getWriter();
            out.print(JSON.toJSON(msg));
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (out != null) {
                out.close();
            }
        }

    }

    public static void returnMsg(HttpServletResponse response, Object msg) {
        PrintWriter out = null;
        try {
            response.setContentType("application/json; charset=utf-8");
            out = response.getWriter();
            out.print(msg);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (out != null) {
                out.close();
            }
        }

    }



}
